package avicit.bdp.dgs.standard.rest;

import avicit.bdp.dgs.standard.dto.DataElementDto;
import avicit.bdp.dgs.standard.dto.LookupTableDto;
import avicit.bdp.dgs.standard.dto.StandardDocDto;
import avicit.bdp.dgs.standard.service.DataElementService;
import avicit.bdp.dgs.standard.service.LookupTableService;
import avicit.bdp.dgs.standard.service.StandardDocService;
import avicit.bdp.dgs.standard.vo.StandardPieVo;
import avicit.bdp.dgs.standard.vo.StateLineChartDataVo;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/bdp/dgs/dataStandard/overview/")
@Api(tags = "标准概览")
public class StandardOverviewRest {

  @Resource private DataElementService dataElementService;
  @Resource private LookupTableService lookupTableService;
  @Resource private StandardDocService standardDocService;

  @ApiOperation(value = "数据项标准总数")
  @GetMapping("dataElementCount")
  public ResponseMsg<Long> dataElementCount(@RequestParam(required = false) Integer status) {
    ResponseMsg<Long> responseMsg = new ResponseMsg<>();
    DataElementDto param = new DataElementDto();
    param.setStatus(status);
    responseMsg.setResponseBody(dataElementService.selectCount(param));
    return responseMsg;
  }

  @ApiOperation(value = "值域标准总数")
  @GetMapping("lookupTableCount")
  public ResponseMsg<Long> lookupTableCount(@RequestParam(required = false) Integer status) {
    ResponseMsg<Long> responseMsg = new ResponseMsg<>();
    LookupTableDto param = new LookupTableDto();
    //param.setStatus(status);
    responseMsg.setResponseBody(lookupTableService.selectCount(param));
    return responseMsg;
  }

  @ApiOperation(value = "标准文件总数")
  @GetMapping("standardDocCount")
  public ResponseMsg<Long> standardDocCount(@RequestParam(required = false) Integer status) {
    ResponseMsg<Long> responseMsg = new ResponseMsg<>();
    StandardDocDto param = new StandardDocDto();
    param.setStatus(status);
    responseMsg.setResponseBody(standardDocService.selectCount(param));
    return responseMsg;
  }

  @ApiOperation(value = "数据元标准状态")
  @GetMapping("dataElementStatusStatics")
  public ResponseMsg<List<StandardPieVo>> dataElementStatusStatics() {
    ResponseMsg<List<StandardPieVo>> responseMsg = new ResponseMsg<>();
    responseMsg.setResponseBody(dataElementService.statusStatics());
    return responseMsg;
  }

  @ApiOperation(value = "近期标准发布审批情况")
  @ApiImplicitParams({
    @ApiImplicitParam(
        value = "统计维度[周(近7天)/月(近30天)/年(近1年)]",
        name = "dimension",
        dataType = "String",
        allowableValues = "week,month,year",
        required = true),
    @ApiImplicitParam(value = "开始时间", name = "startTime", dataType = "String"),
    @ApiImplicitParam(value = "结束时间", name = "endTime", dataType = "String")
  })
  @GetMapping("/lineChart")
  public ResponseMsg<StateLineChartDataVo> lineChart(
      @RequestParam String dimension,
      @RequestParam(required = false) String startTime,
      @RequestParam(required = false) String endTime) {

    ResponseMsg<StateLineChartDataVo> responseMsg = new ResponseMsg<>();
    StateLineChartDataVo result = dataElementService.lineChart(dimension, startTime, endTime);
    responseMsg.setResponseBody(result);
    return responseMsg;
  }
}
